//
//  MYHTabBarController.m
//  MYHBaseFoundation
//
//  Created by 毛云河 on 2018/9/8.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "MYHTabBarController.h"

@interface MYHTabBarController ()<UITabBarControllerDelegate,UIAlertViewDelegate>

@end

@implementation MYHTabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self configTabBar];
    [self creadeTabBarItem];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.hidesBottomBarWhenPushed = YES;
}

- (void)configTabBar
{
    //1，设置tabbar的背景颜色
    self.tabBar.barTintColor = [UIColor whiteColor];
    //2，设置tabbar系统自带的半透明 YES打开半透明 NO关闭半透明 (打开半透明的话，会影响设置颜色的纯度)
    [UITabBar appearance].translucent = NO;;
    //3，设置tabbar的代理
    self.delegate = self;
}

- (void)creadeTabBarItem
{
    //1，创建子控制器
    MainController *home = [[MainController alloc]init];
    //2，把子控制器添加到导航的根视图上
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:home];
    nav1.view.backgroundColor = TotalWhite;
   // 3，隐藏系统自带导航，为了根据需求自定义导航
    nav1.navigationBar.hidden = YES;
    //4，添加到Tabbar上面
    [self addChildVC:nav1 title:@"首页" image:@"Home" selectImage:@"HomeSelect"];
    
    GoodsController *test = [[GoodsController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:test];
    nav2.navigationBar.hidden = YES;
    [self addChildVC:nav2 title:@"商品" image:@"Goods" selectImage:@"GoodsSelect"];
    
    
    MySelfController *myself = [[MySelfController alloc] init];
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:myself];
    nav3.navigationBar.hidden = YES;
    [self addChildVC:nav3 title:@"我的" image:@"My" selectImage:@"MySelect"];
}

#pragma mark - 添加封装子控制器的方法
- (void)addChildVC:(UIViewController *)childVC
             title:(NSString *)title
             image:(NSString *)image
       selectImage:(NSString *)selectImage
{
    //BaseNavigationController *navi = [[BaseNavigationController alloc]initWithRootViewController:childVC];
    //navi.navigationBar.hidden = YES;
    //1，设置标题
    childVC.title = title;
    //2，设置图标
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    childVC.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    //3，需要设置照片的模式，用照片原图，默认是蓝色的
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //4，创建修改字体颜色的字典，同时可以设置字体的内边距；
//    //未选中的字体颜色
//    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
//    textAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:123/255 green:123/255 blue:123/255 alpha:1];
//    //选中的字体颜色
//    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
//    selectedTextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    //添加到Item
//    [navi.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
//    [childVC.tabBarItem setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];
    
    [childVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromHex(0xA4A4A4),NSFontAttributeName:FontWithSize(10)}forState:UIControlStateNormal];
    [childVC.tabBarItem setTitleTextAttributes: @{NSForegroundColorAttributeName:titleColor,NSFontAttributeName:FontWithSize(10)} forState:UIControlStateSelected];
    
    //5，设置自控制器的背景颜色
    childVC.view.backgroundColor = RGBACOLOR(4, 2, 14, 1);
    //6，不要忘记添加到父控制器上
    [self addChildViewController:childVC];
}


#pragma mark - TabBarController的代理 选择当前tabbar的方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}



@end
